//
//  ByNetConfig.m
//  Homept_ios
//
//  Created by pro on 16/9/21.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByNetConfig.h"

#import "ByNetConfigApi.h"          // 全局配置api


@implementation ByNetConfig

#pragma mark - set
+ (void)setGlobalConfig {
    
    // 请求网上的配置数据
    [ByNetConfigApi requestRemoteGlobalConfigSuccess:^(ByNetBaseResult *result) {
        NSMutableArray *allKeys = [[NSMutableArray alloc] init];
        // 把全部对应的键值对 存入到数据库中
        for (NSString *key in [result.data allKeys]) {
            NSString *value = [result.data valueForKey:key];
            [ByCoreCacheSqlite3 setObjectWithKey:key value:value expireTime:3600 * 24];
            
            [allKeys addObject:key];
        }
        
        [ByCoreCacheSqlite3 setObjectWithKey:@"ALL_CONFIG_KEYS" value:allKeys]; // 所有键名存入
    } failure:nil];
}


#pragma mark - get

/** 获得全部的配置 */
+ (NSDictionary *)getAllConfig {
    
    NSArray *allKeys = [ByCoreCacheSqlite3 getValueWithKey:@"ALL_CONFIG_KEYS"]; // 把所有键名取出
    NSMutableDictionary *allConfig = [[NSMutableDictionary alloc] init];
    for (NSString *key in allKeys) {
        id value = [ByCoreCacheSqlite3 getValueWithKey:key];
        if (value) {
            [allConfig setObject:value forKey:key];
        }
    }
    return allConfig;
    
}
/** 客服电话 */
+ (NSString *)getCustomerPhone {
    
    NSDictionary *dictionary = [self getAllConfig];
    NSDictionary *customer_phoneDic = dictionary[@"CUSTOMER_PHONE"];
    NSString *customerPhone = nil;

    customerPhone = customer_phoneDic[@"tel"];
    return customerPhone;
}

+ (NSString *)getAppVersion {
    
    NSDictionary *dictionary = [self getAllConfig];
    NSString *latestVersion = dictionary[@"IOS_VERSION"];
    return latestVersion;
}




@end
